package org.lhg.activiti.util;

public class CodeMessage {
    private int code;
    private String message;
    //通用模块
    public static CodeMessage SUCCESS = new CodeMessage(0, "success");
    public static CodeMessage SERVER_ERROR = new CodeMessage(101, "服务端错误");
    //登录错误
    public static CodeMessage PASSWORD_EMPTY = new CodeMessage(201, "登录密码不能为空");
    public static CodeMessage USER_NOT_EXIT = new CodeMessage(204, "用户不存在");
    public static CodeMessage PASSWORD_ERROR = new CodeMessage(205, "密码输入错误");

    //绑定异常（JSR303校验异常处理）
    public static CodeMessage BIND_ERROR = new CodeMessage(301,"参数校验有误 ：%s");

    //操作异常
    public static CodeMessage PARAM_IS_EMPTY = new CodeMessage(401, "请求参数异常，请核查");

    public CodeMessage(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 返回JSR303的绑定错误信息
     * @param args 返回信息，一般是String
     * @return CodeMessage
     */
    public CodeMessage getBindErrorCodeMsg(Object...args){

        int code = this.code;
        String message = String.format(this.message,args);
        return new CodeMessage(code,message);
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

}
